﻿using JNPF.Basics.Logic;
using JNPF.Basics.Models;
using JNPF.Basics.Models.WorkFlow.Dtos.FlowDelegate;
using JNPF.Utils;
using JNPF.Utils.Controller;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace JNPF.Basics.Controller
{
    /// <summary>
    /// 流程委托
    /// 版 本：V3.0.0
    /// 版 权：引迈信息技术有限公司（https://www.jnpfsoft.com）
    /// 作 者：JNPF开发平台组
    /// 日 期：2018-06-25
    /// </summary>
    [Route("api/WorkFlow/[controller]")]
    public class FlowDelegateController : BaseApiController
    {
        private FlowDelegateBll flowDelegateBll = new FlowDelegateBll();

        #region GET
        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="input">请求参数</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResponseResult> GetList([FromQuery] PageInput input)
        {
            var data = await flowDelegateBll.GetList(input);
            var output = new PageResult()
            {
                list = data.list.MapToList<FlowDelegeteListOutput>(),
                pagination = data.pagination
            };
            return Success(output);
        }

        /// <summary>
        /// 信息
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public async Task<ResponseResult> GetInfo(string id)
        {
            var data = (await flowDelegateBll.GetInfo(id)).MapTo<FlowDelegeteInfoOutput>();
            return Success(data);
        }
        #endregion

        #region POST
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns></returns>
        [HttpDelete("{id}")]
        public async Task<ResponseResult> Delete(string id)
        {
            var entity = await flowDelegateBll.GetInfo(id);
            if (entity != null)
            {
                await flowDelegateBll.Delete(entity);
            }
            return Success("删除成功");
        }

        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="input">实体对象</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResponseResult> Create([FromBody] FlowDelegeteCrInput input)
        {
            var entity = input.MapTo<FlowDelegateEntity>();
            await flowDelegateBll.Create(entity);
            return Success("新建成功");
        }

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="id">主键值</param>
        /// <param name="input">实体对象</param>
        /// <returns></returns>
        [HttpPut("{id}")]
        public async Task<ResponseResult> Update(string id, [FromBody] FlowDelegeteUpInput input)
        {
            var entity = input.MapTo<FlowDelegateEntity>();
            await flowDelegateBll.Update(id, entity);
            return Success("更新成功");
        }
        #endregion
    }
}